# -*- coding: utf-8 -*-
"""展示如何向 AgentOS 传递额外配置的示例。"""
from agno.models.openai import OpenAILike

from configs.basic_config import ALI_GENERATION_MODEL, AGENT_URL, ALI_DASHSCOPE_API_KEY
from pathlib import Path

from agno.agent import Agent
# from agno.db.postgres import PostgresDb
from agno.knowledge.knowledge import Knowledge
from agno.os import AgentOS
from agno.team import Team
# rom agno.vectordb.pgvector import PgVector
from agno.workflow.step import Step
from agno.workflow.workflow import Workflow

# 获取配置文件的路径
cwd = Path(__file__).parent
config_file_path = str(cwd.joinpath("config.yaml"))

# 设置数据库
# db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

# 设置基础代理、团队和工作流
basic_agent = Agent(
    name="基础代理",
    # db=db,
    enable_session_summaries=True,
    enable_user_memories=True,
    add_history_to_context=True,
    num_history_runs=3,
    add_datetime_to_context=True,
    markdown=True,
)
basic_team = Team(
    id="basic-team",
    name="基础团队",
    # --- 修改模型参数 ---
    model=OpenAILike(id=ALI_GENERATION_MODEL, name=ALI_GENERATION_MODEL, api_key=ALI_DASHSCOPE_API_KEY, base_url=AGENT_URL),
    # db=db,
    members=[basic_agent],
    enable_user_memories=True,
)
basic_workflow = Workflow(
    id="basic-workflow",
    name="基础工作流",
    description="一个简单的工作流",
    #db=db,
    steps=[
        Step(
            name="step1",
            description="一个简单的步骤",
            agent=basic_agent,
        )
    ],
)
basic_knowledge = Knowledge(
    name="基础知识库",
    description="一个基础的知识库",
    # contents_db=db,
    # vector_db=PgVector(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai", table_name="vectors"),
)

# 设置我们的 AgentOS 应用
agent_os = AgentOS(
    description="示例 AgentOS",
    agents=[basic_agent],
    teams=[basic_team],
    workflows=[basic_workflow],
    knowledge=[basic_knowledge],
    # 我们在此处将配置文件传递给 AgentOS
    config=config_file_path,
)
app = agent_os.get_app()


if __name__ == "__main__":
    """运行我们的 AgentOS。

    您可以在以下地址查看配置和可用应用：
    http://localhost:7777/docs
    http://localhost:7777/config
    
    
    api test:
    http://localhost:7777/agents/
    http://localhost:7777/agents/
    

    """
    agent_os.serve(app="config_use:app", reload=True)